local HY = require "packages.touhou_hy.utility.utility"
local U = require "packages.utility.utility"
local extension = Package:new("touhou_animals")
extension.extensionName = "touhou_hy"

Fk:loadTranslationTable {
    ["touhou_animals"] = "畜生仲间",
}


local card_publicize = fk.CreateSkill {
    name = "card_publicize",
}
card_publicize:addEffect(fk.AfterCardsMove, {
    mute = true,
    priority = 2,
    global = true,
    can_trigger = function(self, event, target, player, data)
        if not HY.CheckEnabled(player.room) then
            return false
        end
        if table.any(data, function(move)
                return table.any(move.moveInfo, function(info)
                    return info.is_publicized
                end)
            end) then
            return false
        end
        event:setCostData(self, {})
        for _, move in ipairs(data) do
            for _, info in ipairs(move.moveInfo) do
                local card = Fk:getCardById(info.cardId, true)
                if card and (card:getMark("@@card_publicize") > 0 or info.fromArea == Card.PlayerJudge or info.fromArea == Card.PlayerEquip) then
                    table.insertIfNeed(event:getCostData(self), info.cardId)
                end
            end
        end
        return #event:getCostData(self) > 0
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        local room = player.room
        for _, move in ipairs(data) do
            for _, info in ipairs(move.moveInfo) do
                if table.contains(event:getCostData(self), info.cardId) then
                    room:setCardMark(Fk:getCardById(info.cardId), "@@card_publicize", 0)
                    info.is_publicized = true
                end
            end
        end
        HY.UpdatePublicizedCards(room)
    end,
})
card_publicize:addEffect("visibility", {
    global = true,
    card_visible = function(self, player, card)
        if card:getMark("@@card_publicize") > 0 and Fk:currentRoom():getCardArea(card) == Card.PlayerHand then
            return true
        end
    end
})
extension:loadSkillSkels { card_publicize }

local function loadGeneral(name)
    require("packages.touhou_hy.pkgs.animals.generals." .. name)(extension, HY, U)
end

loadGeneral("hy_kurokoma_saki")
loadGeneral("hy_kudamaki_tsukasa")
loadGeneral("hy_doremi_sweet")
loadGeneral("hy_komano_aun")
loadGeneral("hy_inaba_tewi")
loadGeneral("hy_misuteia_rorerai")
loadGeneral("hy_x_komeiji_satori")
loadGeneral("hy_x_komeiji_koishi")

return extension
